package com.zzl.mircoservice.application1.controller;

import com.zzl.microservice.service1.api.ConsumerService;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * description: RESTful API
 * @author 朱正磊
 * @date 2022-07-14 16:10:41
 */
@RestController
public class Application1Controller {

    /**
     * ConfigurableApplicationContext可以实现配置的动态更新，@Value注解做不到
     */
    @Resource
    private ConfigurableApplicationContext applicationContext;

    /**
     * 注入dubbo服务
     */
    @org.apache.dubbo.config.annotation.Reference
    private ConsumerService consumerService;

    /**
     * description: 测试nacos服务器的配置动态更新
     * @author 朱正磊
     * @date 2022-07-16 20:04:42
     * @return 返回nacos配置信息
     */
    @GetMapping("/service")
    public String service() {
        return applicationContext.getEnvironment().getProperty("xxx");
    }

    /**
     * description: 测试调用dubbo服务
     * @author 朱正磊
     * @date 2022-07-16 20:05:20
     * @return 返回字符串
     */
    @GetMapping("/service1")
    public String service1() {
        return "test " + consumerService.service();
    }

}
